package com.enjoy.concurrent.ch1.base.safeend;

/**
 * 实现Runnable接口的线程如何中断
 */
public class EndRunnable {
    private static class UseRunnable implements Runnable{

        @Override
        public void run() {
            if (!Thread.currentThread().isInterrupted()) {
                System.out.println(Thread.currentThread().getName() + " I am implements Runnable");
            }
            System.out.println(Thread.currentThread().getName() + " interrupt flag is "+Thread.currentThread().isInterrupted());
        }

    }

    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = new UseRunnable();
        Thread endThread = new Thread(runnable, "endThread");
        endThread.start();
        Thread.sleep(20);
        endThread.interrupt();

    }
}
